package com.zk.monitormanagement.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zk.monitormanagement.R;
import com.zk.monitormanagement.bean.MonitorBean;

import java.util.List;

public class MyAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;
    List<MonitorBean.DataBean> litTile;

    public MyAdapter(Context context, List<MonitorBean.DataBean> listTile) {
        layoutInflater = LayoutInflater.from(context);
        this.litTile = listTile;
    }

    @Override
    public int getCount() {
        return litTile==null?0:litTile.size();
    }

    @Override
    public Object getItem(int position) {
        return litTile.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.layout_item,null);
            holder.title = (TextView) convertView.findViewById(R.id.tv_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.title.setText(litTile.get(position).getUnitname());
        return convertView;
    }

    class ViewHolder{
        public TextView title;
    }
}
